<template>
  <div class="shop-detail">
    <table class="table_list1 table_list">
      <tr class="table_list_tr table_list_trf">
        <td colspan="2">门店基础信息</td>
      </tr>
      <tr class="table_list_tr">
        <td style="width:50%">门店名称：{{shopMessageList.shopName}}</td>
        <td>门店编号：{{shopMessageList.shopCode}}</td>
      </tr>
      <tr class="table_list_tr">
        <td>所在区域：{{shopMessageList.province}}{{shopMessageList.city}}{{shopMessageList.area}}</td>
        <td>详细地址：{{shopMessageList.address}}</td>
      </tr>
    </table>
    <div class="tb_map">
      <div class="tb_map_tit">地图位置：</div>
      <div class="tb_map_cot">
        <baidu-map class="bm-view"
                   ak="scRvm7dsu17R5Dg1XjC79F9634GvzUVQ"
                   :scroll-wheel-zoom="true"
                   :center="center"
                   :zoom="15"
                   @ready="handler"
                   v-if='mapShow'>
          <bm-overview-map anchor="BMAP_ANCHOR_BOTTOM_RIGHT"
                           :isOpen="true"></bm-overview-map>
          <bm-navigation anchor="BMAP_ANCHOR_TOP_LEFT"></bm-navigation>
          <bm-marker :position="center"
                     v-if="initLocation"></bm-marker>
        </baidu-map>
      </div>
    </div>
    <table class="table_list2 table_list">
      <tr class="table_list_tr table_list_trf">
        <td colspan="2">门店服务信息</td>
      </tr>
      <tr class="table_list_tr">
        <td style="width:50%">联系人：{{shopMessageList.contracts}}</td>
        <td>联系电话：{{shopMessageList.telephone}}</td>
      </tr>
      <tr class="table_list_tr">
        <td>人均消费：{{shopMessageList.peopleConsumption}}</td>
        <td>营业时间：{{shopMessageList.businessHours}}</td>
      </tr>
      <tr class="table_list_tr">
        <td>简拼：{{shopMessageList.spelling}}</td>
        <td>门店性质：{{['直营','非直营','加盟'][shopMessageList.shopProperty]}}</td>
      </tr>
      <tr class="table_list_tr">
        <td>邮编：{{shopMessageList.postCode}}</td>
        <td>传真号码：{{shopMessageList.fax}}</td>
      </tr>
    </table>
    <div class="special">
      <dl>
        <dd>授权密码：{{shopMessageList.authorizedPassword}}</dd>
        <dd style="border-left: 0">
          <div>特色推荐：</div>
          <p class="content">{{shopMessageList.characteristic}}</p>
        </dd>
      </dl>
    </div>
    <div class="tb_des">
      <dl>
        <dd>
          <div style="width: 90px">店面营销标签：</div>
          <p>{{shopMessageList.marketingLabel}}</p>
        </dd>
        <dd style="border-left: 0">
          <div>门店介绍：</div>
          <p>{{shopMessageList.shopIntroduce}}</p>
        </dd>
      </dl>
    </div>
    <div class="tb_des tb_des_img">
      <dl>
        <dt>
          <span>门店图片：</span>
          <div style="margin: 15px 0 0 58px">
            <div class="img-container"><img :src="shopMessageList.shopImage"
                   alt=""></div>
          </div>
        </dt>
      </dl>
    </div>
    <div class="shop_back"><Button class="btn"
              @click="cancel">返回</Button></div>
  </div>
</template>

<script>
import { area_array, sub_array } from '@/libs/area-data'
import { shopDetailMessage } from '@/api/setting'
import { BaiduMap, BmOverviewMap, BmNavigation, BmMarker } from 'vue-baidu-map'
import { routeEqual } from '@/libs/util'
export default {
  name: 'store_detail',
  components: {
    BaiduMap, BmOverviewMap, BmNavigation, BmMarker
  },
  data () {
    return {
      shopMessageList: {},
      center: { lng: 0, lat: 0 },
      initLocation: false,
      mapShow: false
    }
  },
  methods: {
    handler ({ BMap, map }) {
      this.initLocation = true
    },
    closeModal () {
      this.$store.commit('closeTag', this.$route)
      this.$store.commit('setTagNavList', this.$store.state.app.tagNavList.filter(item => !routeEqual(this.$route, item)))
      this.$nextTick(() => {
        this.$router.push({
          name: 'store_list'
        })
      })
    },
    cancel () {
      this.closeModal()
    }
  },
  mounted () {
    let data = { 'merchantId': this.$store.state.user.merchantId, shopId: this.$route.params.id }
    shopDetailMessage(data).then(res => {
      if (res.data.status === 200) {
        this.shopMessageList = res.data.data
        let provinceList = area_array
        if (res.data.data.province !== null) {
          sub_array.forEach((ele, index) => {
            if (Number(this.shopMessageList.province) === index) {
              ele.forEach((val, idx) => {
                if (Number(this.shopMessageList.city) === idx) {
                  this.shopMessageList.city = val
                }
              })
            }
          })
          this.shopMessageList.province = provinceList[this.shopMessageList.province]
        }
        this.center.lng = this.shopMessageList.longitude
        this.center.lat = this.shopMessageList.latitude
        this.mapShow = true
      } else {
        this.$Message.error(`${res.data.error}`)
      }
    })
  }
}
</script>
<style lang="less" scoped>
.shop-detail {
  padding: 40px 125px 47px 107px;
  table,
  th,
  td {
    border: 1px solid #e9e9e9;
  }
  .table_list {
    width: 100%;
    min-width: 960px;
    font-size: 12px;
    border-collapse: collapse;
    color: #464c5b;
    .table_list_tr {
      height: 48px;
      line-height: 48px;
      > td {
        padding-left: 48px;
      }
    }
    .table_list_trf {
      font-size: 14px;
      height: 40px;
      line-height: 40px;
      background: #f8f8f9;
      > td {
        padding-left: 32px;
        height: 40px;
        span {
          display: inline-block;
        }
        .content {
          overflow: hidden;
          text-overflow: ellipsis; //溢出用省略号显示
          white-space: nowrap; //溢出不换行
        }
      }
    }
  }
  .table_list2 {
    margin-top: 40px;
  }
  .tb_map {
    width: 100%;
    min-width: 960px;
    height: 300px;
    border: 1px solid #e8eaec;
    padding-top: 15px;
    padding-left: 48px;
    border-top: none;
    .tb_map_tit {
      font-size: 12px;
      color: #464c5b;
      line-height: 17px;
    }
    .tb_map_cot {
      width: 50%;
      height: 200px;
      margin-left: 70px;
      margin-top: 10px;
      // background: red;
      .bm-view {
        width: 100%;
        height: 200px;
      }
    }
  }
  .tb_des {
    width: 100%;
    min-width: 960px;
    dl {
      display: -webkit-box;
      display: -moz-box;
      display: -webkit-flex;
      display: -moz-flex;
      display: -ms-flexbox;
      flex-wrap: wrap;
      dd,
      dt {
        padding: 16px 14px 22px 48px;
        line-height: 17px;
        list-style: none;
        font-size: 12px;
        color: #464c5b;
        border-left: 1px solid rgb(233, 233, 233);
        border-bottom: 1px solid rgb(233, 233, 233);
        border-right: 1px solid rgb(233, 233, 233);
      }
      dd {
        width: 50%;
        // height: 72px;
        display: -webkit-box;
        display: -moz-box;
        display: -webkit-flex;
        display: -moz-flex;
        display: -ms-flexbox;
        display: flex;
      }
      p {
        -moz-box-flex: 1;
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
        // overflow: hidden;
        // text-overflow: ellipsis; //溢出用省略号显示
        // white-space: wrap; //溢出不换行
        // display: -webkit-box;
        // -webkit-line-clamp: 2;
        // -webkit-box-orient: vertical;
      }
      dt {
        width: 100%;
        height: 232px;
      }
    }
  }
  .special {
    width: 100%;
    min-width: 960px;
    dl {
      display: flex;
      dd {
        padding: 16px 14px 22px 48px;
        width: 50%;
        // height: 49px;
        // line-height: 49px;
        border-left: 1px solid rgb(233, 233, 233);
        border-bottom: 1px solid rgb(233, 233, 233);
        border-right: 1px solid rgb(233, 233, 233);
        display: flex;
      }
      p {
        -moz-box-flex: 1;
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
        // overflow: hidden;
        // text-overflow: ellipsis; //溢出用省略号显示
        // white-space: wrap; //溢出不换行
        // display: -webkit-box;
        // -webkit-line-clamp: 1;
        // -webkit-box-orient: vertical;
      }
    }
  }
  .tb_des_img {
    .img-container {
      display: table-cell;
      text-align: center;
      vertical-align: middle;
      overflow: hidden;
      width: 120px;
      img {
        width: 100%;
        height: auto;
      }
    }
  }
  .shop_back {
    padding: 20px 0;
    text-align: center;
  }
}
</style>
